package com.lrkj.property.controller;

import com.lrkj.common.annotation.Log;
import com.lrkj.common.core.controller.BaseController;
import com.lrkj.common.core.domain.AjaxResult;
import com.lrkj.common.core.page.TableDataInfo;
import com.lrkj.common.enums.BusinessType;
import com.lrkj.common.utils.poi.ExcelUtil;
import com.lrkj.property.domain.Parking;
import com.lrkj.property.service.IParkingService;
import com.lrkj.property.vo.ParkingVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 车场管理Controller
 *
 * @author yajun_ren
 * @date 2022-03-15
 */
@RestController
@RequestMapping("/property/parking")
@Api(tags = "车场管理")
public class ParkingController extends BaseController {
    @Autowired
    private IParkingService parkingService;

    /**
     * 查询车场管理列表
     */
    @ApiOperation(value = "查询车场管理列表", notes = "查询车场管理列表")
    @PreAuthorize("@ss.hasPermi('property:parking:list')")
    @GetMapping("/list")
    public TableDataInfo list(Parking parking) {
        startPage();
        this.changeParameter(parking.getParams());
        List<Parking> list = parkingService.selectParkingList(parking);
        return getDataTable(list);
    }

    /**
     * 导出车场管理列表
     */
    @ApiOperation(value = "导出车场管理列表", notes = "导出车场管理列表")
    @PreAuthorize("@ss.hasPermi('property:parking:export')")
    @Log(title = "车场管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Parking parking) {
        List<Parking> list = parkingService.selectParkingList(parking);
        ExcelUtil<Parking> util = new ExcelUtil<Parking>(Parking.class);
        return util.exportExcel(list, "车场管理数据");
    }

    /**
     * 获取车场管理详细信息
     */
    @ApiOperation(value = "获取车场管理详细信息", notes = "获取车场管理详细信息")
    @PreAuthorize("@ss.hasPermi('property:parking:query')")
    @GetMapping(value = "/{parkingId}")
    public AjaxResult getInfo(@PathVariable("parkingId") String parkingId) {
        return AjaxResult.success(parkingService.selectParkingById(parkingId));
    }

    /**
     * 新增车场管理
     */
    @ApiOperation(value = "新增车场管理", notes = "新增车场管理")
    @PreAuthorize("@ss.hasPermi('property:parking:add')")
    @Log(title = "车场管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Parking parking) {
        return toAjax(parkingService.insertParking(parking));
    }

    /**
     * 修改车场管理
     */
    @ApiOperation(value = "修改车场管理", notes = "修改车场管理")
    @PreAuthorize("@ss.hasPermi('property:parking:edit')")
    @Log(title = "车场管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Parking parking) {
        return toAjax(parkingService.updateParking(parking));
    }

    /**
     * 删除车场管理
     */
    @ApiOperation(value = "删除车场管理", notes = "删除车场管理")
    @PreAuthorize("@ss.hasPermi('property:parking:remove')")
    @Log(title = "车场管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{parkingIds}")
    public AjaxResult remove(@PathVariable String[] parkingIds) {
        return toAjax(parkingService.deleteParkingByIds(parkingIds));
    }


    /**
     * 通过车场ID,获取车场内车位数量和使用情况
     */
    @ApiOperation(value = "通过车场ID,获取车场内车位数量和使用情况", notes = "通过车场ID,获取车场内车位数量和使用情况")
    @GetMapping(value = "/getParkingCarport/{parkingId}")
    public AjaxResult getParkingCarport(@PathVariable("parkingId") String parkingId) {
        return AjaxResult.success(parkingService.getParkingCarport(parkingId));
    }

    /**
     * 新增车场数量
     */
    @ApiOperation(value = "新增车场数量", notes = "新增车场数量")
    @PostMapping("/addParkingNum")
    public AjaxResult addParkingNum(@RequestBody ParkingVo parkingVo){
        return toAjax(parkingService.addParkingNum(parkingVo));
    }




}
